package com.xkdx.guangguang.fragment.shop.search;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.Shop;

public class SearchShopModule extends AbsModule {
	List<Shop> list;

	@Override
	public void parseData() throws Exception {
		backJson = (JSONArray) result;
		try {
			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("searchShopList")) {
					list = parseShopList(jsonObj.getJSONObject("Content"));
				}

			}
		} catch (Exception e) {
			// TODO: handle exception
		}

	}

	private List<Shop> parseShopList(JSONObject person) throws Exception{
		ArrayList<Shop> list = new ArrayList<Shop>();
		try {
			JSONObject stut = (JSONObject) person.get("Result");
			JSONArray listInfo = stut.getJSONArray("ListInfo");

			for (int i = 0; i < listInfo.length(); i++) {
				JSONObject item = (JSONObject) listInfo.opt(i);
				Shop shop = new Shop();
				List<String> listIcon = new ArrayList<String>();

				shop.setAddress(item.getString("Address"));
				shop.setDistance(item.getString("Distance"));
				shop.setLatitude(item.getString("Latitude"));
				shop.setLogo(item.getString("Logo"));
				shop.setLongitude(item.getString("Longitude"));
				shop.setShopID(item.getString("ShopID"));
				shop.setShopName(item.getString("ShopName"));

				shop.setIcon1(item.getString("Icon1"));

				shop.setIcon2(item.getString("Icon2"));

				shop.setIcon3(item.getString("Icon3"));

				if (!"False".equals(shop.getIcon1())) {
					listIcon.add("1");
				}
				if (!"False".equals(shop.getIcon2())) {
					listIcon.add("2");
				}
				if (!"False".equals(shop.getIcon3())) {
					listIcon.add("3");
				}
				shop.setIcon(listIcon);

				list.add(shop);

			}

		} catch (Exception e) {
			throw e;
		}
		return list;
	}

}
